package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/18.
 */

public class TransactionDetailsActivityAdapter extends BaseAdapter {

    private Context mContext;
    List<BuyACarFragmentModel> model= new ArrayList<>();
    public TransactionDetailsActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<BuyACarFragmentModel> model){
        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.itme_transaction_details, null);
            holder.time = (TextView) convertView
                    .findViewById(R.id.time);
            holder.item_moneys = (TextView) convertView
                    .findViewById(R.id.item_moneys);
            holder.item_balance = (TextView) convertView
                    .findViewById(R.id.item_balance);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        BuyACarFragmentModel bModel = model.get(position);
        if (bModel.getPraise().equals("")){
            holder.item_title.setText(Html.fromHtml(bModel.getName()));
        }else {
            holder.item_title.setText(Html.fromHtml(bModel.getName()+"&emsp<font color='#555555'>"+bModel.getPraise()+"</font>"));
        }

        holder.item_balance.setText(bModel.getLet());
        holder.time.setText(bModel.getDistance());
        if (bModel.getDate().equals("0")){
            holder.item_moneys.setText(Html.fromHtml("<font color='#00BFDE'>"+bModel.getMoney1()+"</font>"));
        }else {
            holder.item_moneys.setText(Html.fromHtml("<font color='#FF4537'>"+bModel.getMoney1()+"</font>"));
        }
        return convertView;
    }

    class ViewHolder {

        TextView item_title;
        TextView item_balance;
        TextView time;
        TextView item_moneys;



    }
}


